﻿@model BackEnd.Models.SearchArtistModel
@{
    ViewBag.Title = "Artist Management";
}
 <h2>
        Artist Management</h2>
@using (Html.BeginForm())
{ 
    @Html.ValidationSummary(true, "Artist creation was unsuccessful. Please correct the errors and try again.", new { @class="error_box" }) 
                        
    
    <div>
                   
            <table width="100%" cellspacing="0" cellpadding="5" border="0" id="table6">
                <tr>
                    <td>
                        <label>Artist's Name</label>
                    </td>
                    <td>
                        @Html.TextBoxFor(m => m.KeyWord)
                    </td>
                    <td>
                        <label>Country</label>
                    </td>
                    <td>
                        @Html.DropDownListFor(m => m.Country, new SelectList(Model.ListCountry, "Id", "Country"))
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>Born</label>
                    </td>
                    <td>
                        @Html.TextBoxFor(m => m.Born)
                    </td>
                    <td>
                        <label>Died</label>
                    </td>
                    <td>
                        @Html.TextBoxFor(m => m.Died)
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="submit" class="NFButton NFh" value="Search" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
                    </td>
                </tr>
            </table>
        
    </div>
}    
    <a class="bt_green" href="/Artist/Create"><span class="bt_green_lft"></span><strong>Create</strong><span class="bt_green_r"></span></a>
    <a class="bt_red" href="#" onclick="DeleteSelectedItems(this);"><span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span></a>    
    <p>
        @if (ViewData["ErrorMessage"] != null)
           {
        @Html.Label(ViewData["ErrorMessage"].ToString())
        }
    </p>

    <table id="rounded-corner"><thead>
        <tr>
            <th class="rounded-company" scope="col">
                <input id="chkAll" onclick="javascript: SelectAll(this);" type="checkbox" />
            </th>
            <th class="rounded" scope="col">
                Full Name
            </th>
            <th class="rounded" scope="col">
                First Name
            </th>
             <th class="rounded" scope="col">
                Middle Name
            </th>
            <th class="rounded" scope="col">
                Last Name
            </th>
            <th class="rounded" scope="col">
                Born
            </th>
             <th class="rounded" scope="col">
                Died
            </th>
            <th class="rounded" scope="col">
                Country
            </th>
            <th class="rounded" scope="col">
                Affiliate ID
            </th>
            <th class="rounded" scope="col">
                Date created
            </th>
            <th class="rounded" scope="col">
                List Price
            </th>
            <th class="rounded-q4" scope="col">
            </th>
        </tr>
        @foreach (var item in Model.ListOfArtist)
           {
        <tr>
            <td>
                @Html.CheckBox("check", new { itemid = item.ArtistId, refer = "chk", onclick = "javascript:SelectOne(this)" })
            </td>
            <td>
                @HttpUtility.HtmlDecode(item.FullName)
            </td>
            <td>
                @HttpUtility.HtmlDecode(item.FirstName)
            </td>
             <td>
                @HttpUtility.HtmlDecode(item.MiddleName)
            </td>
            <td>
               @HttpUtility.HtmlDecode(item.LastName)
            </td>
            <td>
                @item.Born
            </td>
             <td>
                @item.Died
            </td>
            <td>
                @item.Country
            </td>
            <td>
               @item.Affiliate_Id
            </td>
            <td>
                @item.DateCreated
            </td>
            <td>
                @Html.ActionLink("List Price", "ListPriceByArtist", "Price", new { artistId = item.ArtistId }, null)
            </td>
            <td>                
                <a href="/Artist/Edit?id=@item.ArtistId"><img border="0" title="" alt="" src="/Content/Images/user_edit.png"></a>
            </td>
        </tr>
        }
        <tr><td colspan="11"><div>
    Page @(Model.TotalPage < Model.PageIndex ? 0 : Model.PageIndex)
    of @Model.TotalPage
    &nbsp;
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "Index", new { keyword = Server.UrlEncode(Model.KeyWord), born=Model.Born, died = Model.Died, country = Model.Country,page = 1 })
        @Html.Raw("&nbsp;");
        @Html.ActionLink("< Prev", "Index", new { keyword = Server.UrlEncode(Model.KeyWord), born=Model.Born, died = Model.Died, country = Model.Country,page = Model.PageIndex - 1 })
    }
    @*else
  {
        @:<<
        @Html.Raw("&nbsp;");
        @:< Prev
    }
            *@
    &nbsp;
    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "Index", new { keyword = Server.UrlEncode(Model.KeyWord), born=Model.Born, died = Model.Died, country = Model.Country,page = Model.PageIndex + 1 })
        @Html.Raw("&nbsp;");
        @Html.ActionLink(">>", "Index", new { keyword = Server.UrlEncode(Model.KeyWord), born=Model.Born, died = Model.Died, country = Model.Country,page = Model.TotalPage })
    }
    @*
    else
    {
        @:Next >
        @Html.Raw("&nbsp;")
        @:>>
    }*@
</div></td></tr>
        </thead>
    </table>
    <input id="hidDs" type="hidden" />
    <script type="text/javascript">
        /*Check, Check All*/
        function SelectAll(spanChk) {

            var hidSelected = $("input[id='hidDs']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                chk.checked = spanChk.checked;
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
            //alert(hidSelected.val());
        }
        function SelectOne() {
            var hidSelected = $("input[id='hidDs']");
            var chkList = $("input[refer='chk']");
            var str = "";

            for (var i = 0; i < chkList.length; i++) {
                var chk = chkList[i];
                if (chk.checked) {
                    str = str + $(chk).attr("itemid") + "_";
                }
            }
            str = str == "" ? "" : str.substring(0, str.length - 1);
            hidSelected.attr("value", str);
        }
        function DeleteSelectedItems() {
            if (confirm('Are you sure that want delete these items?')) {
                var hidSelected = $("input[id='hidDs']");
                if (hidSelected.val() != "") {

                    var rows = $("input:checked");
                    rows.each(function () {
                        $(this).parent().parent().remove();
                    });

                    var URL = '/Artist/Delete/' + hidSelected.val();
                    $.post(URL, function (data) {
                        //                        alert(data);
                        //                        if (data == "1") {
                        //                            alert("Delete successful");
                        //                            
                        //                        }
                        //                        else {
                        //                            alert("Cannot delete selected items!");
                        //                        }
                    });

                }
            }
        }
    </script>